<?php
// $Id: article.php,v 1.4 2005/08/03 12:39:14 onokazu Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //

include "header.php";

include_once XOOPSNEWSPATH.'/class/class.newsstory.php';

$storyid = (isset($_GET['storyid'])) ? intval($_GET['storyid']) : 0;
if (empty($storyid)) {
    redirect_header("index.php",2,_NW_NOSTORY);
    exit();
}

$xoopsOption['template_main'] = 'news_article.html';

include_once XOOPS_ROOT_PATH.'/header.php';
//wanikoo
$news_module_header = '';
$news_module_header .= '
	<link rel="stylesheet" type="text/css" href="'.newsGetStyleURL("news.css").'" />
	<script src="'.newsGetStyleURL("news.js").'" type="text/javascript"></script>
	';
$news_module_header = $news_module_header; 
$xoopsTpl->assign('xoops_module_header', $news_module_header);
//

$myts =& MyTextSanitizer::getInstance();
// set comment mode if not set


$article = new NewsStory($storyid);
if ( $article->published() == 0 || $article->published() > time() ) {
    redirect_header('index.php', 2, _NW_NOSTORY);
    exit();
}
$storypage = isset($_GET['page']) ? intval($_GET['page']) : 0;
// update counter only when viewing top page
if (empty($_GET['com_id']) && $storypage == 0) {
    $article->updateCounter();
}
$story['id'] = $storyid;
$story['posttime'] = formatTimestamp($article->published());
$story['title'] = $article->textlink()."&nbsp;:&nbsp;".$article->title();
$story['text'] = $article->hometext();
$bodytext = $article->bodytext();

if ( trim($bodytext) != '' ) {
    $articletext = explode("[pagebreak]", $bodytext);
    $story_pages = count($articletext);

    if ($story_pages > 1) {
        include_once XOOPS_ROOT_PATH.'/class/pagenav.php';
        $pagenav = new XoopsPageNav($story_pages, 1, $storypage, 'page', 'storyid='.$storyid);
        $xoopsTpl->assign('pagenav', $pagenav->renderNav());
        //$xoopsTpl->assign('pagenav', $pagenav->renderImageNav());

        if ($storypage == 0) {
            $story['text'] = $story['text'].'<br /><br />'.$articletext[$storypage];
        } else {
            $story['text'] = $articletext[$storypage];
        }
    } else {
        $story['text'] = $story['text'].'<br /><br />'.$bodytext;
    }
}

$story['poster'] = $article->uname();
if ( $story['poster'] ) {
    $story['posterid'] = $article->uid();
    $story['poster'] = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$story['posterid'].'">'.$story['poster'].'</a>';
} else {
    $story['poster'] = '';
    $story['posterid'] = 0;
    $story['poster'] = $xoopsConfig['anonymous'];
}
$story['morelink'] = '';
$story['adminlink'] = '';
unset($isadmin);
if ( $xoopsUser && $xoopsUser->isAdmin($xoopsModule->getVar('mid')) ) {
    $isadmin = true;
    $story['adminlink'] = $article->adminlink();
}
$story['topicid'] = $article->topicid();
$story['imglink'] = '';
$story['align'] = '';
if ( $article->topicdisplay() ) {
    $story['imglink'] = $article->imglink();
    $story['align'] = $article->topicalign();
}
$story['hits'] = $article->counter();
//$story['mail_link'] = 'mailto:?subject='.sprintf(_NW_INTARTICLE,$xoopsConfig['sitename']).'&amp;body='.sprintf(_NW_INTARTFOUND, $xoopsConfig['sitename']).':  '.XOOPSNEWSURL.'/article.php?storyid='.$article->storyid();
$story['mail_link'] = 'mailto:?subject='.rawurlencode(sprintf(_NW_INTARTICLE,$xoopsConfig['sitename'])).'&amp;body='.rawurlencode(sprintf(_NW_INTARTFOUND, $xoopsConfig['sitename']).':  '.XOOPSNEWSURL.'/article.php?storyid='.$article->storyid());
$xoopsTpl->assign('story', $story);
$xoopsTpl->assign('lang_printerpage', _NW_PRINTERFRIENDLY);
$xoopsTpl->assign('lang_sendstory', _NW_SENDSTORY);
$xoopsTpl->assign('lang_on', _ON);
$xoopsTpl->assign('lang_postedby', _POSTEDBY);
$xoopsTpl->assign('lang_reads', _READS);
//$xoopsTpl->assign('mail_link', 'mailto:?subject='.sprintf(_NW_INTARTICLE,$xoopsConfig['sitename']).'&amp;body='.sprintf(_NW_INTARTFOUND, $xoopsConfig['sitename']).':  '.XOOPSNEWSURL.'/article.php?storyid='.$article->storyid());
$xoopsTpl->assign('mail_link', 'mailto:?subject='.rawurlencode(sprintf(_NW_INTARTICLE,$xoopsConfig['sitename'])).'&amp;body='.rawurlencode(sprintf(_NW_INTARTFOUND, $xoopsConfig['sitename']).':  '.XOOPSNEWSURL.'/article.php?storyid='.$article->storyid()));

include XOOPS_ROOT_PATH.'/include/comment_view.php';

//wanikoo theme changer
$xoopsTpl->assign("lang_themechanger", _NW_THEMECHANGER);
$mynewstheme_options = '';

    foreach ($GLOBALS['news_allowed_theme'] as $mynewstheme) {
        $mynewstheme_options .= '<option value="'.$mynewstheme.'"';
        if ($mynewstheme == $GLOBALS['news_theme']) {
            $mynewstheme_options .= ' selected="selected"';
        }
        $mynewstheme_options .= '>'.$mynewstheme.'</option>';
    }

    $newstheme_select = '<select name="news_theme_select" onchange="submit();" size="1">'.$mynewstheme_options.'</select>';

$xoopsTpl->assign("newsthemeoption", $newstheme_select);

//wanikoo search
if ( file_exists(XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/search.php") ) {
   include_once XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/search.php";
} else {
   include_once XOOPS_ROOT_PATH."/language/english/search.php";
}
$xoopsTpl->assign('lang_all', _SR_ALL);
$xoopsTpl->assign('lang_any', _SR_ANY);
$xoopsTpl->assign('lang_exact', _SR_EXACT);
$xoopsTpl->assign('lang_search', _SR_SEARCH);
$xoopsTpl->assign('module_id', $xoopsModule->getVar('mid'));
//category head
$catarray = array();
if ( $news_show_letters ) {
$catarray['letters'] = news_letters();
}
if ( $news_show_toolbar ) {
$catarray['toolbar'] = news_toolbar();
}
$xoopsTpl->assign('catarray', $catarray);

//pagetitle (module name - news title)
$xoopsTpl->assign('xoops_pagetitle', $xoopsModule->getVar('name').' - '.$article->title());

//ver3.0 topic navi
if ( $xoopsModuleConfig['displaynav'] == 1 ) {
	$xoopsTpl->assign('displaynav', true);
	$xt = new XoopsTopic($xoopsDB->prefix('topics'));
	ob_start();
	$xt->makeTopicSelBox(1, $article->topicid(), 'storytopic');
	$topic_select = ob_get_contents();
	ob_end_clean();
	$xoopsTpl->assign('topic_select', $topic_select);
} else {
	$xoopsTpl->assign('displaynav', false);
}
$xoopsTpl->assign('lang_go', _GO);
//more search 
if (file_exists(XOOPS_ROOT_PATH."/include/moremetasearch.php")&&$news_show_externalsearch) {
	include_once XOOPS_ROOT_PATH."/include/moremetasearch.php";
	$_REQUEST['query']= $article->title();
	$engineblocktitle = _NW_EXTERNALSEARCH;
	$engineblocktitle .= sprintf(_NW_EXTERNALSEARCH_KEYWORD, $article->title());
	$location_list=moremeta("meta_page","on");
	$metaresult = more_meta_page($location_list, $target="_blank", $display = false, $engineblocktitle);
	$xoopsTpl->assign('moremetasearch', "<br /><br />".$metaresult);
}
else {
	$xoopsTpl->assign('moremetasearch', '');
}
//
if (file_exists(XOOPSNEWSPATH."/include/xoopssearchform.php")&&$news_show_xoopssearch) {
	$keyword4xoopssearch = $article->title();
	include_once XOOPSNEWSPATH."/include/xoopssearchform.php";
	$result4xoopssearch = $search_form->render();
	$xoopsTpl->assign('morexoopssearch', "<br /><br />".$result4xoopssearch);
}
else {
	$xoopsTpl->assign('morexoopssearch', '');
}


include_once XOOPSNEWSPATH."/footer.php";


?>